package com.xiaoxin.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoxin.framework.aspectj.lang.annotation.DataSource;
import com.xiaoxin.framework.aspectj.lang.enums.DataSourceType;
import com.xiaoxin.framework.web.controller.BaseController;
import com.xiaoxin.framework.web.page.PageUtils;
import com.xiaoxin.framework.web.page.TableDataInfo;
import com.xiaoxin.project.system.domain.ExDeviceInfo;
import com.xiaoxin.project.system.domain.SysDept;
import com.xiaoxin.project.system.domain.SysUser;
import com.xiaoxin.project.system.service.SysUserService;
import com.xiaoxin.project.system.service.impl.ExDeviceInfoServiceImpl;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Talk is cheap Show me the code
 * @version 1.0
 * @data 2021/5/20 22:27
 */
@Api(tags = "系统用户")
@RestController
@RequestMapping("/api/user")
@Slf4j
public class SysUserController extends BaseController {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private ExDeviceInfoServiceImpl exDeviceInfoService;

    @ApiResponses({
            @ApiResponse(code = 0000, message = "成功"),
            @ApiResponse(code = 0001, message = "无功能权限"),
            @ApiResponse(code = 0002, message = "参数校验有误"),
            @ApiResponse(code = 0003, message = "业务逻辑异常"),
            @ApiResponse(code = 9999, message = "runtime异常")
    })
    @ApiOperation(value = "查看部门")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "datestring", value = "日期", required = true, dataType = "string", paramType = "query", example = "xingguo"),
            @ApiImplicitParam(name = "tableName", value = "表名称", required = true, dataType = "string"),
    })
    @GetMapping("/odsSmallDefine")
    public TableDataInfo<SysDept> odsSmallDefine(
            @RequestParam(value = "datestring", required = true) String datestring,
            @RequestParam(value = "tableName", required = true) String tableName) {

        TableDataInfo rspData = new TableDataInfo();
        List<SysDept> sysDepts = new ArrayList<>();
        sysDepts.add(new SysDept());
        rspData.setRows(sysDepts);
        return rspData;
        //return AjaxResult.success(new SysDept());
    }

    @GetMapping()
    public TableDataInfo<SysUser> getUserList(
            @RequestParam(value = "pageNum", required = false) String pageNum,
            @RequestParam(value = "pageSize", required = false) String pageSize) {

        return sysUserService.getUserList();
    }

    @GetMapping("/getExList")
    @ApiOperation(value = "getExList")
    public TableDataInfo<ExDeviceInfo> getExList(
            @RequestParam(value = "pageNum", required = false) String pageNum,
            @RequestParam(value = "pageSize", required = false) String pageSize) {
        List<ExDeviceInfo> exList = exDeviceInfoService.getExList();
        return PageUtils.getDataTable(exList);
    }

    /**
     * description: 分页列表
     * @param current
     * @param size
     * @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page
     * @time: 2022/1/17 19:11
     */
    @RequestMapping("/page")
    @DataSource(value = DataSourceType.SLAVE)
    public Page<ExDeviceInfo> page(@RequestParam int current,@RequestParam int size) {
/*    public TableDataInfo<ExDeviceInfo> page(@RequestParam int current,@RequestParam int size) {
        List<ExDeviceInfo> exList = exDeviceInfoService.getExList2();
        return PageUtils.getDataTable(exList);*/
        return exDeviceInfoService.page(new Page<>(current,size), new QueryWrapper(new ExDeviceInfo()));
    }

}
